package 装饰模式.商场促销实例;



/**
 * @author zyl
 * @Description
 * @since 2023/12/26 13:54
 */

public class CashContext {
    private ISale iSale;

    public CashContext(int cashType) {
        switch (cashType){
            case 1:
                this.iSale = new CashNormal();
                break;
            case 2:
                this.iSale = new CashRebate(0.8d);
                break;
            case 3:
                this.iSale = new CashRebate(0.7d);
                break;
            case 4:
                this.iSale = new CashReturn(300d,100d);
                break;
            case 5:
                //先打折再返利
                CashNormal cashNormal = new CashNormal();
                CashReturn cashReturn = new CashReturn(300d,100d);
                CashRebate cashRebate = new CashRebate(0.8);
                cashReturn.decorate(cashNormal);
                cashRebate.decorate(cashReturn);
                this.iSale = cashRebate;
                break;
        }
    }
    public double getPriceResults(double price, int num){
        return this.iSale.acceptCash(price, num);
    }
}
